package algorithms.paixu;



/**
 * @功能
 * @创建时间 2021/1/9
 * 顺序查找（基于链表
 */
public class SequentialSearchST<Key,Value> {
    private Node first;
    private class Node{
        Key key;
        Value val;
        Node next;

        public Node(Key key, Value val, Node next) {
            this.key = key;
            this.val = val;
            this.next = next;
        }
    }
    public Value get(Key key){
        for (Node x = first;x!=null;x = x.next)
            if(key.equals(x.key))
                return x.val;
        return null;
    }

    public void put(Key key,Value val){
        for (Node x = first; x!= null;x = x.next)
            if (key.equals(x.key)){
                x.val = val;
                return; //更新
            }
        first = new Node(key,val,first); // 未命中，新建节点
    }


}
